<template>
    <el-radio-group v-bind="$attrs">
        <template v-for="op in options_c" :key="op.id">
            <el-radio :label="op.id">{{op.title}}</el-radio>
        </template>
    </el-radio-group>
</template>

<script setup lang="ts">

import {computed, useAttrs} from "vue";

const props = withDefaults(defineProps<{
    options?: any
}>(), {
    options: [{id:1,title:'是'},{id:0, title:'否'}]
})

const attrs = useAttrs()

// 根据modelValue的类型，重新结算options中id的类型
const options_c = computed(()=>{

    let itemArr = props.options;
    // console.log("eeee",options)
    // if (options instanceof Object) {
    //
    //     for (let key in options){
    //         itemArr.push({id:key, title:options[key]})
    //     }
    // } else if (options instanceof String){
    //     let list = options.split(',')
    //     itemArr = list.map(item => {
    //         return {id: item, title: item}
    //     })
    // }else if (options instanceof Array){
    //     itemArr = options
    // }

    // 对itemArr进行再处理
    if(typeof attrs.modelValue == 'number'){
        // 将 options中的id强制转为number
        for(let i in itemArr){
            itemArr[i].id = Number(itemArr[i].id)
        }
    }else if(typeof attrs.modelValue == 'string'){
        // 强制转为string
        for(let i in itemArr){
            itemArr[i].id = String(itemArr[i].id)
        }
    }


    return itemArr
})

</script>

<style scoped>

</style>